﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Reflection;
using System.Data;

namespace IKYSWeb.Yetki
{
    public partial class ManuelCacheTemizle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                CacheListesiOlustur();
        }
        private void CacheListesiOlustur()
        {
            lstCache.Items.Clear();
            List<DictionaryEntry> oList = new List<DictionaryEntry>();
            foreach (object item in HttpContext.Current.Cache)
            {
                oList.Add(((DictionaryEntry)item));
                if (((DictionaryEntry)item).Value is DataSet)
                {
                    lstCache.Items.Add(new ListItem(
                        ((DictionaryEntry)item).Key.ToString() + " (" +
                        ((DataSet)(((DictionaryEntry)item).Value)).Tables[0].Rows.Count.ToString() + ")",
                        ((DictionaryEntry)item).Key.ToString()));
                }
                else
                    lstCache.Items.Add(new ListItem(((DictionaryEntry)item).Key.ToString(),
                       ((DictionaryEntry)item).Key.ToString()));
            }
        }
        protected void btnSecileniTemizle_Click(object sender, EventArgs e)
        {
            if (txtSifre.Text == "cachetemizle")
            {
                foreach (ListItem item in lstCache.Items)
                {
                    if (item.Selected)
                        HttpContext.Current.Cache.Remove(item.Value);
                }
                CacheListesiOlustur();
            }
        }
        protected void btnTumunuTemizle_Click(object sender, EventArgs e)
        {
            if (txtSifre.Text == "cachetemizle")
            {
                foreach (ListItem item in lstCache.Items)
                {
                    HttpContext.Current.Cache.Remove(item.Value);
                }
                CacheListesiOlustur();
            }
        }
    }
}
